<?php
      
   
	if(empty($_GET['ptype']))
		$ptype = 'article';
	else 	
		$ptype = $_GET['ptype'];
	
	if(!empty($_GET['cmd']))
		$cmd = $_GET['cmd'];
	else
		$cmd = ''; 


  if(!empty($_GET['id']))
  		$id=$_GET['id'];
	else
		$id = '';
		
	global $conf;
	if(!isset($auth_session->user_data['user_level']) || $auth_session->user_data['user_level']<8)
		header("location:admin");
	
	$editor = new editor;
	
			if(!empty($_POST))
			{
				
				
		
				//get media processor
				$conf->a['photo-dir']="media/images/";
				$conf->a['thumb-dir']="media/images/";

				include 'admin/m/media/p_media_content.php';
	   		
	   		$conf->a['photo-dir']="../media/images/";
				$conf->a['thumb-dir']="../media/images/";
	        
	         if(empty($_POST['id']))
	         {
	         	$post['type']='post';	
					process_sql_post($post,'content','add',NULL,NULL);
					printmessage("content added");					
					
					$o['order'][0]="id";
					$o['order'][1]="DESC";

					$w[0]='type';
					$w[1]='post';
					$w[2]='=';
					$where[] = $w;
										
					$row=get_sql('content','id',$where,$o);
					//die($row);					
					$r = current($row);
					
					$post['id']=$r['id'];
					$id = $r['id'];
					process_sql_post($post,'content_post','add',NULL,NULL);
					printmessage("content_post added");
					process_sql_post($post,'content_meta','add',NULL,NULL);
					printmessage("content_meta added");
					process_sql_post($post,'content_access','add',NULL,NULL);
									
					if(!empty($image_data))
					{
						printmessage('adding image');		
						$image_data['id']=$id;
						process_sql_post($image_data,'content_image','add',NULL,NULL);		
					}
					else
					{
						printmessage('No image selected, adding default image');
						$image_data['id']=$id;
						$image_data['image']='20110511_sgv-pinoytuner-site-update-may-2011.jpg';
						$image_data['thumb']='20110511_iwb-pinoytuner-site-update-may-2011.jpg';
						process_sql_post($image_data,'content_image','add',NULL,NULL);
								
					}
					
				}
				else
				{
					process_sql_post($post,'content','update','id',$id);
					printmessage("content updated");					
					process_sql_post($post,'content_post','update','id',$id);
					printmessage("content_post updated");
					process_sql_post($post,'content_meta','update','id',$id);
					printmessage("content_meta updated");				
					if(!empty($image_data))
					{
						printmessage('Replacing Image Data');
						$image_data['id']=$id;
						process_sql_post($image_data,'content_image','update','id',$id);	
						
					
					}
				}
			}	


//default values
	
	$e['status']='enabled';
	$e['start']=date("Y-m-d h:i:s");
	$e['end'] = mktime(0, 0, 0, date("m")+12,   date("d"),   date("Y"));
	$e['end']=date("Y-m-d h:i:s",$e['end']);
	$e['weight']=0;
	$e['access_currency']='USD';
	$e['access_cost']=0;
	$e['access_expiry']=48;
	$e['delivery']='vod';
	$e['buffer']=30;
	$e['owner']=$_SESSION['user_id'];						
	$e['resize_image']='0';
	$e['index']=false;
	$e['playlist']=0;
	$e['category']=18;
	$e['post_type']=$ptype;
	$e['resize_x_thumb']=60;
	$e['resize_y_thumb']=60;
	$e['resize_thumb']='1';
	if($cmd=='edit')
	{
		$editor->get_edit_content($id);
		$edit = $editor->edit;
		$edit_image = $editor->edit_image;
		$edit_meta = $editor->edit_meta;
		$e['title'] = $edit['title'];
		$e['author'] = $edit['author'];
		$e['content'] = $edit['content'];
		$e['secondary'] = $edit['secondary'];
		$e['image'] = $edit_image['image'];
		$e['thumb'] = $edit_image['thumb'];
		$e['rating'] = $edit['rating'];	
		$e['meta_title'] = $edit_meta['meta_title'];
		$e['meta_searchtitle'] = $edit_meta['meta_searchtitle'];
		$e['meta_description'] = $edit_meta['meta_description'];
		$e['meta_keywords'] = $edit_meta['meta_keywords'];
		$e['meta_searchdescription'] = $edit_meta['meta_searchdescription'];
		
			
				
	}
	
  
	
  
	
	
	$editor->get_literary_content($ptype);
	$editor->get_all_post();
	$lit = $editor->literary;
	 
	$conf->play=true;  
  
?>